const app = getApp(),url = app.globalData.url;
Page({

  /**
   * 页面的初始数据
   */
  data: {
		listdata:[],
		where:{
			pageNum :1,
			pageSize :7,
		}
  },
	detail(e){
    var that = this
    let did = e.currentTarget.dataset.id
    that.data.where.pageNum = 1
    wx.navigateTo({
      url: '/HomePage/workdetail/workdetail?id='+did,
    })
  },
  onLoad: function (options) {
		let obj = wx.getStorageSync('objdata')
		this.setData({where:obj})
		this.getData()
	},
	getData(){
		let _this = this
    wx.showLoading({ title: '加载中' })
		wx.request({
			// url: 'https://www.qugouzhigong.top/dgdx-Api/position/findWorkListXcx',
			url: url + 'position/findWorkListXcx',
			method:'POST',
			data: this.data.where,
			success(res){
				wx.hideLoading()
				let resData = res.data
				if(!resData || !resData.data){
					return
				}
				let listdata = (resData.data.content || []).filter(item => item.id)
				if(_this.data.where.pageNum > 1 && listdata.length === 0){
          wx.showToast({
            title: '到底了~~',
            icon:'none'
          })
          return
        }
        _this.setData({
          listdata: [..._this.data.listdata, ...listdata]
        })

				_this.setData({ listdata })
				setTimeout(function(){
					wx.removeStorage({key: 'objdata',})
				},1000)
			},
			fail(err){
				wx.hideLoading()
			}
		})
	},
	listpage(){
		var that = this
		var where = that.data.where
		var listdata = that.data.listdata
		that.data.where.pageNum ++
		wx.request({
			url: url + 'position/findWorkList',
			method:'POST',
			data: where,
			success: function(res)
			{
				console.log(res)
				var ret = res.data
				if(ret.data.content != ''){
					listdata=listdata.concat(ret.data.content)
					that.setData({listdata})
				}else{
					wx.showToast({
						title: '没有更多了~',
						icon:'none'
					})
				}
				// listdata=listdata.concat(ret.data.content)
        // that.setData({listdata})
				// that.setData({listdata:res.data.data.content})
				
			},
			fail:function(res){
				console.log(res)

			}
		})
	},
	onReachBottom () {
		this.data.where.pageNum++
		this.setData({
			where: this.data.where
		})
		this.getData()
    // var that = this
    // that.listpage()
	},
	onHide: function () {
    var that = this
    that.data.where.pageNum = 1
  },

  onUnload: function () {
    var that = this
    that.data.where.pageNum = 1
  },
})